feat(type-extensions): add support for converting additional numeric types #250
+83
−19
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
When using the
GetFieldValue
method, the following exceptions throw:If the value in the database is stored as
System.Int64
and the target type isSystem.SByte
, this will result in an exception:If the value in the database is stored as
System.Int64
and the target type isSystem.UInt16
, this will result in an exception:If the value in the database is stored as
System.Int64
and the target type isSystem.Single
, this will result in an exception:If the value in the database is stored as
System.Int64
and the target type isSystem.Double
, this will result in an exception:If the value in the database is stored as
System.Int64
and the target type isSystem.Decimal
, this will result in an exception:The same applies if the conversion should happen vice versa.
What is the new behavior?
Conversion without exceptions.
Does this PR introduce a breaking change?
Other information
This issue was discovered through
unit tests
.EFCoreSecondLevelCacheInterceptor/src/Tests/EFCoreSecondLevelCacheInterceptor.UnitTests/TypeExtensionsTests.cs
Line 88 in 8aecbf6
EFCoreSecondLevelCacheInterceptor/src/Tests/EFCoreSecondLevelCacheInterceptor.UnitTests/EFTableRowsDataReaderTests.cs
Line 1438 in 8aecbf6
This happens because the
IsNumber
method in theTypeExtensions
class supports a limited set of numeric types:EFCoreSecondLevelCacheInterceptor/src/EFCoreSecondLevelCacheInterceptor/TypeExtensions.cs
Line 112 in 8aecbf6
The change adds the following types:
sbyte
ushort
float
double
decimal
As an example, we can take
SqliteValueReader
, which works correctly in these cases:https://github.com/dotnet/efcore/blob/a0443c1460e33f76094a30dc5ae0524743ed02f5/src/Microsoft.Data.Sqlite.Core/SqliteValueReader.cs#L223
https://github.com/dotnet/efcore/blob/a0443c1460e33f76094a30dc5ae0524743ed02f5/src/Microsoft.Data.Sqlite.Core/SqliteValueReader.cs#L248
https://github.com/dotnet/efcore/blob/a0443c1460e33f76094a30dc5ae0524743ed02f5/src/Microsoft.Data.Sqlite.Core/SqliteValueReader.cs#L320
https://github.com/dotnet/efcore/blob/a0443c1460e33f76094a30dc5ae0524743ed02f5/src/Microsoft.Data.Sqlite.Core/SqliteValueReader.cs#L315
https://github.com/dotnet/efcore/blob/a0443c1460e33f76094a30dc5ae0524743ed02f5/src/Microsoft.Data.Sqlite.Core/SqliteValueReader.cs#L310
Best Regards,
Dmitrii Kiselev